package com.eshop.modules.product.rest;

import org.springframework.web.bind.annotation.DeleteMapping;
import com.eshop.modules.aop.ForbidSubmit;
import java.io.Serializable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import com.eshop.enums.ShopCommonEnum;
import java.util.Date;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.validation.annotation.Validated;
import com.eshop.modules.product.domain.StoreProductReply;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import io.swagger.annotations.ApiOperation;
import com.eshop.logging.aop.log.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.product.service.dto.StoreProductReplyQueryCriteria;
import com.eshop.modules.product.service.StoreProductReplyService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;

@Api(tags = { "商城:评论管理" })
@RestController
@RequestMapping({ "api" })
public class StoreProductReplyController
{
    private final StoreProductReplyService storeProductReplyService;
    
    public StoreProductReplyController(final StoreProductReplyService storeProductReplyService) {
        this.storeProductReplyService = storeProductReplyService;
    }
    
    @Log("查询")
    @ApiOperation("查询")
    @GetMapping({ "/yxStoreProductReply" })
    @PreAuthorize("hasAnyRole('admin','YXSTOREPRODUCTREPLY_ALL','YXSTOREPRODUCTREPLY_SELECT')")
    public ResponseEntity getYxStoreProductReplys(final StoreProductReplyQueryCriteria criteria, final Pageable pageable) {
        return new ResponseEntity(this.storeProductReplyService.queryAll(criteria, pageable), HttpStatus.OK);
    }
    
    @Log("修改")
    @ApiOperation("修改")
    @PutMapping({ "/yxStoreProductReply" })
    @PreAuthorize("hasAnyRole('admin','YXSTOREPRODUCTREPLY_ALL','YXSTOREPRODUCTREPLY_EDIT')")
    public ResponseEntity update(@Validated @RequestBody final StoreProductReply resources) {
        resources.setMerchantReplyTime(new Date());
        resources.setIsReply(ShopCommonEnum.REPLY_1.getValue());
        this.storeProductReplyService.updateById(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }
    
    @ForbidSubmit
    @Log("删除")
    @ApiOperation("删除")
    @DeleteMapping({ "/yxStoreProductReply/{id}" })
    @PreAuthorize("hasAnyRole('admin','YXSTOREPRODUCTREPLY_ALL','YXSTOREPRODUCTREPLY_DELETE')")
    public ResponseEntity delete(@PathVariable final Long id) {
        this.storeProductReplyService.removeById((Serializable)id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
